import { Component, OnInit } from '@angular/core';
import { ModalConfirmService } from '../../../@shared/components/modal-confirm';
// import { CurrencyMaskInputMode } from '../../../@core/directive/currency.model';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';

function ageValidator(c: AbstractControl): { [key: string]: any } | null {
  let num = c.value;
  if (/^[0-9]$/.test(num) && num > 0) {
    return null;
  }
  return { numberInvalid: true };
}

@Component({
  selector: 'app-modal-bs',
  templateUrl: './modal-bs.component.html',
  styleUrls: ['./modal-bs.component.scss'],
})
export class ModalBsComponent implements OnInit {
  form: FormGroup;

  constructor(private fb: FormBuilder, private modalConfirmService: ModalConfirmService) {}

  ngOnInit() {
    this.form = this.fb.group({
      amount: [0, ageValidator],
    });
  }

  onSubmit({ value, valid }: { value: Object; valid: boolean }) {
    console.log(value, valid);
  }

  onOpenModal() {
    this.modalConfirmService.open({
      config: {
        ignoreBackdropClick: true,
      },
      content: '是否删除?',
      onOk: () => {},
    });
  }
}
